from Editor import *
import string,regsub
import WordExpand

place_holder='/*@*/'

def unquote(str):
	str=regsub.gsub('@@','\001',str)
	str=regsub.gsub('@',place_holder,str)
	str=regsub.gsub('\001','@',str)
	return str

def GotoNextPlaceHolder(backward=0):
	sel=GetSelection()
	patt=regsub.gsub('[][\\?*+^$]','\\\\\\0',place_holder)
	s,e=Search(patt,GetSelectionStart(),backward)
	if (s,e)==sel:
		s,e=Search(patt,GetSelectionEnd(),backward)
	if s<0:
		s,e=Search(patt,0,backward)
	if s>=0:
		SetSelection(s,e)


def RegisterKeywordExpansion(abbrevs,*filetypes):
	"""abbrevs is a string with syntax expansions.
	"""
	syntaxlist=string.split(unquote(abbrevs),'----\n')
	for ft in filetypes:
		WordExpand.SetKeywords(ft,syntaxlist)

